// src/features/workspaces/api/use-get-workspaces.ts
import {MARK_DATA_URL} from "@/lib/social/constants";
import qs from "query-string";
import {usePathname, useRouter, useSearchParams} from "next/navigation";

interface Props {
    wid?: string
    uid?: string
}

export const useGetWorkspaces = async (props?: Props) => {
    // let baseURL = `${MARK_DATA_URL}/workspaces`
    let baseURL = `/api/workspaces`
    if (props) {
        if (props.wid || props.uid) {
            if (props.wid && !props.uid) baseURL = `${baseURL}/${props.wid}`
            if (!props.wid && props.uid) baseURL = `${baseURL}?userId=${props.uid}`
            if (props.wid && props.uid) baseURL = `${baseURL}./${props.wid}?userId=${props.uid}`
        }
    }

    const get = async () => {
        const res = await fetch(
            baseURL
        )
        let data = await res.json()
        return data
    }

    return await get()
}